home *** CD-ROM | disk | FTP | other *** search
/ Super Shareware Collection / Super Shareware Collection.iso / info / cad08n10.zip / CHANGEBL.LSP < prev    next >
Lisp/Scheme  |  1994-02-21  |  2KB  |  46 lines

  1. ; program to change a block's definition
  2. ; program prompts for a selection set and then steps through
  3. ; changing all the selected blocks to the one entered from the
  4. ; keyboard
  5. ; the new block takes on all the properties of the old block
  6. ; including the rotation and scale
  7. ;
  8. ; written by Steffen Toxopeus
  9. ;
  10.  
  11. (defun c:changebl ( / blkent blknew blkent inspt counter)
  12.   (prompt "\nSelect the BLOCKS you want to change: ")
  13.   (setq blkset (ssget))
  14.   (if blkset    ;if anything was selected
  15.     (setq blknew (getstring "\nWhat is the name of the new BLOCK?"))
  16.   );if
  17.   (if (and (not (= "" blknew)) blkset)
  18.     (progn
  19.       ; get the insertion point of the first block in the selection set
  20.       (setq inspt (cdr (assoc 10 (entget (ssname blkset 0)))))
  21.       ; insert the new block at that insertion point and erase it
  22.       ; this avoids changing the extents arbitrarially
  23.       (command "insert" blknew inspt "" "" ""
  24.                "erase" "L" ""
  25.       )
  26.       ; now we can step through the blocks and change their assoc
  27.       ; lists with the new block name since the new block is now
  28.       ; defined in the database
  29.       (setq counter 1)
  30.       (while (<= counter (sslength blkset))
  31.         ; get the next block
  32.         (setq blkent (entget (ssname blkset (1- counter)))
  33.           ; change the name of the block in the assoc list
  34.           ; (assoc 2)
  35.           blkent (subst (cons 2 blknew) (assoc 2 blkent) blkent)
  36.           ; while we're about it, clock the counter
  37.           counter (1+ counter)
  38.         );setq
  39.         ; modify the block in the database (and on screen)
  40.         (entmod blkent)
  41.       );while
  42.     );progn
  43.   );if
  44. (princ)
  45. );defun
  46.